package logic

import (
	"context"
	"login-reg/loginrpc/loginrpcclient"

	"login-reg/api/internal/svc"
	"login-reg/api/internal/types"

	"github.com/zeromicro/go-zero/core/logx"
)

type CaptchaApiLogic struct {
	logx.Logger
	ctx    context.Context
	svcCtx *svc.ServiceContext
}

func NewCaptchaApiLogic(ctx context.Context, svcCtx *svc.ServiceContext) *CaptchaApiLogic {
	return &CaptchaApiLogic{
		Logger: logx.WithContext(ctx),
		ctx:    ctx,
		svcCtx: svcCtx,
	}
}

func (l *CaptchaApiLogic) CaptchaApi(req *types.CaptchaRequest) (resp *types.Response, err error) {
	// todo: add your logic here and delete this line
	captcha, err := l.svcCtx.LoginRpc.Captcha(l.ctx, &loginrpcclient.CaptchaRequest{
		Account: req.Account,
	})
	if err != nil {
		return &types.Response{
			Message: err.Error(),
			Code:    500,
			Data:    nil,
		}, nil
	}

	return &types.Response{
		Message: "图片获取成功",
		Code:    200,
		Data:    captcha,
	}, nil
}
